package com.itheima.stock.config;

import com.itheima.stock.utils.IdWorker;
import com.itheima.stock.utils.ParserStockInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author GAQ
 * @create 2022-05-30
 * @Description
 */
@Configuration
public class CommonConfig {

    /**
     * 定义密码加密匹配器配置Bean
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Bean
    public IdWorker idWorker(){
        /*
            参数1：机器id
            参数2：机房id
            将来如果做集群部署的话，部署到不同机房下的机器，保证输入的参数不一致即可
         */
        IdWorker idWorker = new IdWorker(1L, 2L);
        return idWorker;
    }

    /**
     * 定义股票信息类转化bean
     * @param idWorker
     * @return
     */
    @Bean
    public ParserStockInfoUtil parserStockInfoUtil(@Autowired IdWorker idWorker) {
        return new ParserStockInfoUtil(idWorker);
    }
}
